package server.operation.impl;

import net.sf.json.JSONObject;
import server.dao.UserDao;
import server.model.User;
import server.operation.Operation;

/**
 * 登录
 * @author skywalker
 *
 */
public class LoginOperation implements Operation {

	/**
	 * @return user对象生成的json，格式示例:
	 * {"avatar":"","birthday":{"date":29,"day":2,"hours":21,"minutes":29,"month":8,"nanos":0,"seconds":28,"time":1443533368000,"timezoneOffset":-480,"year":115}
	 * ,"id":1,"name":"skywalker","password":"1234","sex":"MALE","signature":"i love you"}
	 */
	public String operate(JSONObject param) {
		String username = param.getString("username");
		String password = param.getString("password");
		User user = UserDao.getInstance().login(username, password);
		JSONObject json = JSONObject.fromObject(user);
		return json.toString();
	}

}
